package com.year_23.april;


/**
 * @author: jsh
 * @create: 2023/4/22 22:15
 * @Description: 1027 最长等差数列
 *              https://leetcode.cn/problems/longest-arithmetic-subsequence/
 *
 * @FileName: Day22
 * @History:
 * @自定义内容： 动态规划
 */
public class Day22 {



    public int longestArithSeqLength(int[] nums) {
        int l = nums.length;
        int[][] dp = new int[l][1001];
        int res = 0;
        for (int i = 1; i < l; i++) {
            for (int j = 0; j < i; j++) {
                //计算差值
                int diff = nums[i] - nums[j] + 500;
                dp[i][diff] = Math.max(dp[i][diff], dp[j][diff] + 1);
                res = Math.max(res, dp[i][diff]);
            }
        }
        return res+1;
    }

}
